//
// Description: 831. KMP字符串
// Created by Loading on 2021/12/19.
//

#include <bits/stdc++.h>

using namespace std;

int main() {
    string s, p;
    int m, n;
    cin >> n >> p >> m >> s;

    // next 数组
    int next[n];
    next[0] = -1;
    for (int i = 1, j = -1; i < n; ++i) {
        while (j > -1 && p[i] != p[j + 1]) {
            j = next[j];
        }
        if (p[i] == p[j + 1]) {
            ++j;
        }
        next[i] = j;
    }

    // 匹配
    for (int i = 0, j = -1; i < m; ++i) {
        while (j > -1 && s[i] != p[j + 1]) {
            j = next[j];
        }
        if (s[i] == p[j + 1]) {
            ++j;
        }
        if (j == n - 1) {
            // 匹配成功
            cout << i - n + 1 << ' ';
            /* 直接后退到next[j]，防止重复匹配 */
            j = next[j];
        }
    }

    return 0;
}
